#ifndef DATA_H
#define DATA_H

#include <stdint.h>
#include <stddef.h>
#include <time.h>


#include "../threadPool/thread_pool.h"

#define RCV_DATA_MAX_LEN 1024
#define MAX_EVENTS 1024

enum Protocol{
    PROTOCOL_NONE = 0,
    PROTOCOL_MODBUS = 1 << 0,
    PROTOCOL_DLT645 = 1 << 1,
    PROTOCOL_IEC101 = 1 << 2,
    PROTOCOL_IEC104 = 1 << 3
};

typedef uint8_t RCV_DATA_TYPE;

typedef enum {
    DEVICE_STATE_UNREGISTERED,
    DEVICE_STATE_REGISTERED
} DeviceState;

typedef struct {
    int sock_fd;
    DeviceState state;
    uint8_t reg_code;
    RCV_DATA_TYPE rcv_data[RCV_DATA_MAX_LEN];
    ssize_t rcv_len;
    RCV_DATA_TYPE sent_data[RCV_DATA_MAX_LEN];
    ssize_t sent_len;
    struct timespec last_request_time;
    struct itimerspec collect_interval_time;
    uint8_t pending_requests;
}DeviceContext;

typedef struct {
    int a;
    int b;
}DeviceData;

typedef struct {
    DeviceContext *ctx;
    uint8_t argeement_type;
    DeviceData data;
}Device;

typedef struct DeviceNode {
    Device *device;
    struct DeviceNode *next;
} DeviceNode;


void device_destory(Device *dev);
int Init_timer_epoll();
#endif